home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / include / user / RCS / stdio.h,v < prev    next >
Encoding:
Text File  |  1992-07-17  |  13.4 KB  |  426 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  srv030:1.2 srv027:1.2 srv026:1.2 srv024:1.2 srv021:1.2 srv019:1.2 srv018:1.2 srv016:1.2 srv014:1.2 srv010:1.2 srv008:1.2 srv007:1.2 srv006:1.2 srv005:1.2 srv004:1.2 srv003:1.2 srv002:1.2 srv001:1.2;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     92.03.23.14.19.27;  author kupfer;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     92.03.20.22.21.01;  author kupfer;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @@
  22.  
  23.  
  24. 1.2
  25. log
  26. @Add support for sprited.
  27. @
  28. text
  29. @/*
  30.  * stdio.h --
  31.  *
  32.  *    This header file declares the stdio library facilities.  They
  33.  *    provide a general stream facility and routines for formatted
  34.  *    input and output.
  35.  *
  36.  * Copyright 1986, 1988 Regents of the University of California
  37.  * Permission to use, copy, modify, and distribute this
  38.  * software and its documentation for any purpose and without
  39.  * fee is hereby granted, provided that the above copyright
  40.  * notice appear in all copies.  The University of California
  41.  * makes no representations about the suitability of this
  42.  * software for any purpose.  It is provided "as is" without
  43.  * express or implied warranty.
  44.  *
  45.  * $Header: /user5/kupfer/spriteserver/include/user/RCS/stdio.h,v 1.1 92/03/20 22:21:01 kupfer Exp Locker: kupfer $ SPRITE (Berkeley)
  46.  */
  47.  
  48. #ifndef _STDIO_H
  49. #define _STDIO_H
  50.  
  51. /* 
  52.  * sprite.h is needed for typedefs that are used in some function
  53.  * prototypes.  Unfortunately, some user programs define conflicting
  54.  * typedefs.  Because practically everyone uses stdio.h, only include
  55.  * <sprite.h> if function prototypes are enabled (i.e. we're in the
  56.  * kernel or the user has explicitly asked for prototypes).
  57.  */
  58. #include <cfuncproto.h>
  59.  
  60. #ifdef _HAS_PROTOTYPES
  61. #include <sprite.h>
  62. #endif
  63.  
  64. #ifndef EOF
  65. #define EOF (-1)
  66. #endif
  67.  
  68. #ifndef NULL
  69. #define NULL 0
  70. #endif
  71.  
  72. #ifndef _CLIENTDATA
  73. typedef int *ClientData;
  74. #define _CLIENTDATA
  75. #endif
  76.  
  77. #ifndef _VA_LIST
  78. #define _VA_LIST
  79. typedef char *va_list;
  80. #endif
  81.  
  82. /*
  83.  * The main data structure used by the stdio module is a FILE.  This
  84.  * describes a byte-sequential communication channel.  The channel
  85.  * includes buffer storage and the names of three stream-dependent
  86.  * procedures:
  87.  *
  88.  * The procedure readProc is called when another byte of data is needed
  89.  * and the buffer is empty (readCount == 0).  It should read more data
  90.  * into the buffer, reset readCount and lastAccess, and set the STDIO_EOF
  91.  * flag and/or status field if any problem occurred while reading the data.
  92.  *
  93.  * The writeProc procedure is similar to readProc, except that it is
  94.  * called when the buffer has filled (writeCount just became zero);
  95.  * its job is to write out the contents of the buffer and reset
  96.  * lastAccess and writeCount.  If the flush parameter is non-zero, then
  97.  * the procedure is being called as part of fflush, and it MUST empty
  98.  * the buffer.  Otherwise, the procedure may, if it chooses, increase
  99.  * the size of the buffer and return without actually writing anything.
  100.  *
  101.  * The third procedure, closeProc, is called when the stream is closed
  102.  * (writeProc is also called on close, before closeProc).  CloseProc
  103.  * should take any client-specific closing actions, such as closing
  104.  * the file corresponding to the stream or freeing the buffer space
  105.  * for the stream.  Its return value will be the return value from
  106.  * the fclose call.  If an error occurs while closing the stream, then
  107.  * the FILE structure should not be de-allocated, since the client will
  108.  * need to get at information in it to find out what went wrong.
  109.  *
  110.  * The procedures have the following calling sequences:
  111.  *
  112.  *    void readProc(stream)
  113.  *        FILE *stream;
  114.  *    {
  115.  *    }
  116.  
  117.  *    void writeProc(stream, flush)
  118.  *        FILE *stream;
  119.  *        Boolean flush;
  120.  *    {
  121.  *    }
  122.  
  123.  *    int closeProc(stream)
  124.  *        FILE *stream;
  125.  *    {
  126.  *    }
  127.  *
  128.  * See StdIoFileReadProc, StdIoFileWriteProc, and StdIoFileCloseProc for
  129.  * examples of these procedures.
  130.  */
  131.  
  132. typedef struct _file {
  133.     unsigned char *lastAccess;    /* Place (in buffer) from which last input
  134.                  * or output byte was read or written
  135.                  * (respectively). */
  136.     int readCount;        /* # of characters that may be read from
  137.                  * buffer before calling readProc to refill
  138.                  * the buffer. */
  139.     int writeCount;        /* # of characters that may be written into
  140.                  * buffer before calling writeProc to empty
  141.                  * the buffer.  WriteProc is called immediately
  142.                  * when the buffer fills, so that this value
  143.                  * is never zero unless the stream is not
  144.                  * currently being used for writing. */
  145.     unsigned char *buffer;    /* Pointer to storage for characters.  NULL
  146.                  * means storage hasn't been allocated yet. */
  147.     int bufSize;        /* Total number of bytes of storage available
  148.                  * in buffer. 0 means storage for buffer hasn't
  149.                  * been allocated yet. */
  150.     void (*readProc)_ARGS_((struct _file *));
  151.                 /* Procedure called to refill buffer. */
  152.     void (*writeProc)_ARGS_((struct _file *, Boolean));
  153.                 /* Procedure called to empty buffer. */
  154.     int (*closeProc)_ARGS_((struct _file *));
  155.                 /* Procedure called to close stream.  NULL
  156.                  * means no procedure to call. */
  157.     ClientData clientData;    /* Additional data for the use of the
  158.                  * procedures above,  e.g. the stream ID used
  159.                  * in kernel calls. */
  160.     int status;            /* Non-zero means an error has occurred while
  161.                  * emptying or filling the buffer.  This field
  162.                  * is set by readProc and writeProc. */
  163.     int flags;            /* Miscellaneous flags.  See below for values.
  164.                  */
  165.     struct _file *nextPtr;    /* For file streams, this is used to link all
  166.                  * file streams together (NULL means end of
  167.                  * list).  For other types of streams, it can
  168.                  * be used for anything desired by the
  169.                  * stream implementor. */
  170. } FILE;
  171.  
  172. /* Flags for FILEs:
  173.  *
  174.  * STDIO_READ:        Means that this stream is used for input.
  175.  * STDIO_WRITE:        Means that this stream is used for output.
  176.  * STDIO_EOF:        Means that an end-of-file has been encountered
  177.  *            on this stream.  All future reads will fail.
  178.  * STDIO_LINEBUF:    Means that this stream is line-buffered:  flush when
  179.  *            a newline is output or stdin is read.
  180.  * STDIO_NOT_OUR_BUF:      Means that the buffer for the stream belongs to someone
  181.  *                  else and should not be freed by the stdio library.
  182.  * 
  183.  */
  184.  
  185. #define STDIO_READ        1
  186. #define STDIO_WRITE        2
  187. #define STDIO_EOF        4
  188. #define STDIO_LINEBUF        8
  189. #define STDIO_NOT_OUR_BUF    16
  190.  
  191. /*
  192.  *----------------------------------------------------------------------
  193.  *
  194.  * getc --
  195.  * getchar --
  196.  * putc --
  197.  * putchar --
  198.  *
  199.  *    These four macros are used to input the next character from
  200.  *    a FILE or output the next character to a FILE.  Normally they
  201.  *    just move a character to or from a buffer, but if the buffer is
  202.  *    full (or empty) then they call a slow procedure to empty (or fill)
  203.  *    the buffer.
  204.  *
  205.  *    These macros are somewhat gross. putc is a ternary operator
  206.  *    to allow people to say things like
  207.  *
  208.  *        if (a)
  209.  *              putc(stdout, '\n');
  210.  *        else ...
  211.  *
  212.  *    If it were a complex expression, the compiler would complain.
  213.  *
  214.  * Results:
  215.  *    None.
  216.  *
  217.  * Side effects:
  218.  *    Information is modified in stream's buffer.
  219.  *
  220.  *----------------------------------------------------------------------
  221.  */
  222.  
  223. #ifndef lint
  224. #define getc(stream)                             \
  225.     (((stream)->readCount <= 0) ?                                       \
  226.         fgetc(stream) :                        \
  227.         ((stream)->readCount -= 1,                             \
  228.          (stream)->lastAccess += 1,                        \
  229.          *((stream)->lastAccess)))
  230.  
  231. #define putc(c, stream)                                                \
  232.     ((((stream)->writeCount <= 1) || ((stream)->flags & STDIO_LINEBUF)) ? \
  233.         fputc(c, stream) :                                  \
  234.         ((stream)->writeCount -= 1,                                    \
  235.          (stream)->lastAccess += 1,                                    \
  236.          *(stream)->lastAccess = c))
  237. #else
  238. _EXTERN int getc _ARGS_((FILE stream));
  239. _EXTERN int putc _ARGS_((int c, FILE stream));
  240. #endif
  241.  
  242. #define getchar() getc(stdin)
  243.  
  244. #define putchar(c) putc(c, stdout)
  245.  
  246. /*
  247.  *----------------------------------------------------------------------
  248.  *
  249.  * ferror --
  250.  * feof --
  251.  *
  252.  *    These two macros return information about whether an error
  253.  *    or end-of-file condition has occurred on a stream.
  254.  *
  255.  * Results:
  256.  *    ferror returns 0 if no error has occurred on the stream;
  257.  *    if an error has occurred then it returns the error code.
  258.  *    feof returns 0 if no end-of-file has been encountered on
  259.  *    the stream, and TRUE (non-zero) if an end-of-file has been
  260.  *    encountered.
  261.  *
  262.  * Side effects:
  263.  *    None.
  264.  *
  265.  *----------------------------------------------------------------------
  266.  */
  267.  
  268. #define ferror(stream) ((stream)->status)
  269. #define feof(stream) ((stream)->flags & STDIO_EOF)
  270.  
  271.  
  272. /*
  273.  *----------------------------------------------------------------------
  274.  *
  275.  * Miscellaneous additional things exported by stdio:
  276.  *
  277.  *----------------------------------------------------------------------
  278.  */
  279.  
  280. /*
  281.  * Handles for standard input and output channels.
  282.  */
  283.  
  284. extern FILE stdioInFile, stdioOutFile, stdioErrFile;
  285. #define stdin    (&stdioInFile)
  286. #define stdout    (&stdioOutFile)
  287. #define stderr    (&stdioErrFile)
  288.  
  289. /*
  290.  * Default buffer size:
  291.  */
  292.  
  293. #define BUFSIZ            4096
  294.  
  295. /*
  296.  * Flags to setvbuf:
  297.  */
  298.  
  299. #define _IOFBF        1
  300. #define _IOLBF        2
  301. #define _IONBF        3
  302.  
  303. /*
  304.  * Relative position indicator for fseek:
  305.  */
  306.  
  307. #define SEEK_SET    0
  308. #define SEEK_CUR    1
  309. #define SEEK_END    2
  310.  
  311. /*
  312.  *----------------------------------------------------------------------
  313.  *
  314.  * Procedures exported by the stdio module:
  315.  * (Note that these declarations are missing the "const" modifiers
  316.  * found in the ANSI version...)
  317.  * 
  318.  *----------------------------------------------------------------------
  319.  */
  320.  
  321. _EXTERN void    clearerr _ARGS_((FILE *stream));
  322. _EXTERN int    fclose _ARGS_((FILE *stream));
  323. _EXTERN FILE *    fdopen _ARGS_((int streamID, char *access));
  324. _EXTERN int    fflush _ARGS_((FILE *stream));
  325. _EXTERN int    fgetc _ARGS_((FILE *stream));
  326. _EXTERN char *    fgets _ARGS_((char *bufferPtr, int maxChars, FILE *stream));
  327. _EXTERN int    fileno _ARGS_((FILE *stream));
  328. _EXTERN FILE *    fopen _ARGS_((_CONST char *fileName, _CONST char *access));
  329. _EXTERN int    fputc _ARGS_((int c, FILE *stream));
  330. _EXTERN int    fputs _ARGS_((char *string, FILE *stream));
  331. _EXTERN int    fread _ARGS_((char *bufferPtr, int size, int numItems,
  332.                   FILE *stream));
  333. _EXTERN FILE *    freopen _ARGS_((_CONST char *fileName,
  334.                                 _CONST char *access, FILE *stream));
  335. _EXTERN long    fseek _ARGS_((FILE *stream, int offset, int base));
  336. _EXTERN long    ftell _ARGS_((FILE *stream));
  337. _EXTERN int    fwrite _ARGS_((char *bufferPtr, int size, int numItems,
  338.                    FILE *stream));
  339. _EXTERN char *    gets _ARGS_((char *bufferPtr));
  340. _EXTERN int    getw _ARGS_((FILE *stream));
  341. _EXTERN void    perror _ARGS_((_CONST char *msg));
  342. _EXTERN FILE *    popen _ARGS_((_CONST char *cmd, char *mode));
  343. _EXTERN int    pclose _ARGS_((FILE *ptr));
  344. _EXTERN int      remove _ARGS_((_CONST char *filename));
  345. _EXTERN int      rename _ARGS_((_CONST char *oldname, _CONST char *newname));
  346.  
  347. #if defined(KERNEL) || defined(SPRITED)
  348. /*
  349.  * Special-case declarations for kernels:
  350.  * Printf returns void because the old Sys_Printf did.
  351.  * Varargs declarations aren't easy to do across all machines, so 
  352.  * we'll punt on them for now.
  353.  */
  354. _EXTERN void    printf _ARGS_(());
  355. _EXTERN int    fprintf _ARGS_(());
  356. _EXTERN int    scanf _ARGS_(());
  357. _EXTERN char *    sprintf _ARGS_(());
  358. _EXTERN int    sscanf _ARGS_(());
  359. _EXTERN int    fscanf _ARGS_(());
  360. _EXTERN int    vfprintf _ARGS_(());
  361. _EXTERN int    vfscanf _ARGS_(());
  362. _EXTERN int    vprintf _ARGS_(());
  363. _EXTERN char *    vsprintf _ARGS_(());
  364. #else /* KERNEL */
  365. /* 
  366.  * User-mode declarations for the routines in the special-case section:
  367.  * Note that the prototype declarations are actually no-ops until 
  368.  * _ARGS_ is turned on for user code.  Also, the varargs declarations 
  369.  * are only a first cut; there no guarantee they'll actually work when 
  370.  * _ARGS_ is turned on.
  371.  */
  372. _EXTERN int    printf _ARGS_((_CONST char *format, ...));
  373. _EXTERN int    fprintf _ARGS_((FILE *stream, _CONST char *format, ...));
  374. _EXTERN int    scanf _ARGS_((_CONST char *format, ...));
  375. _EXTERN char *    sprintf _ARGS_((char *s, _CONST char *format, ...));
  376. _EXTERN int    sscanf _ARGS_((char *s, _CONST char *format, ...));
  377. _EXTERN int    fscanf _ARGS_((FILE *stream, _CONST char *format, ...));
  378. _EXTERN int    vfprintf _ARGS_((FILE *stream,
  379.                                  _CONST char *format, va_list args));
  380. _EXTERN int    vfscanf _ARGS_((FILE *stream,
  381.                                 _CONST char *format, va_list args));
  382. _EXTERN int    vprintf _ARGS_((_CONST char *format, va_list args));
  383. _EXTERN char *    vsprintf _ARGS_((char *string,
  384.                                  _CONST char *format, va_list args));
  385. #endif /* KERNEL || SPRITED */
  386.  
  387. _EXTERN int    puts _ARGS_((_CONST char *string));
  388. _EXTERN int    putw _ARGS_((int w, FILE *stream));
  389. _EXTERN void    rewind _ARGS_((FILE *stream));
  390. _EXTERN void    setbuf _ARGS_((FILE *stream, char *buf));
  391. _EXTERN void    setbuffer _ARGS_((FILE *stream, char *buf, int size));
  392. _EXTERN void    setlinebuf _ARGS_((FILE *stream));
  393. _EXTERN int    setvbuf _ARGS_((FILE *stream, char *buf, int mode, int size));
  394. _EXTERN FILE *    tmpfile _ARGS_((void));
  395. _EXTERN char *    tmpnam _ARGS_((char *s));
  396. _EXTERN char *    tempnam _ARGS_((char *dir, char *pfx));
  397. _EXTERN int    ungetc _ARGS_((int c, FILE *stream));
  398. _EXTERN void    _cleanup _ARGS_((void));
  399.  
  400. _EXTERN void    Stdio_Setup _ARGS_((FILE *stream, int readable, int writable,
  401.                 unsigned char *buffer, int bufferSize,
  402.                 void (*readProc)(FILE * file),
  403.                 void (*writeProc)(FILE * file, Boolean flush),
  404.                 int (*closeProc)(FILE * file),
  405.                 ClientData clientData));
  406.  
  407. #endif /* _STDIO_H */
  408. @
  409.  
  410.  
  411. 1.1
  412. log
  413. @Initial revision
  414. @
  415. text
  416. @d17 1
  417. a17 1
  418.  * $Header: /sprite/src/lib/include/RCS/stdio.h,v 1.27 91/12/05 10:44:56 ouster Exp $ SPRITE (Berkeley)
  419. d319 1
  420. a319 1
  421. #ifdef KERNEL
  422. d357 1
  423. a357 1
  424. #endif /* KERNEL */
  425. @
  426.